﻿using System;
using System.Net;

namespace Lunexx.Config
{
    public class WorldSettings
    {

        #region Private Members
        //Default Settings for WorldSocket class
        int port = 15551;
        string listenIP = "127.0.0.1";
        string serverHost = "u-lunia-lb00.pubgame.ijji.com";
        IPAddress serverIP = null;

        #endregion
        #region Public Members
        public string ListenIPString
        {
            get { return listenIP; }
            set { listenIP = value; }
        }
        public int Port
        {
            get { return port; }
            set { port = value; }
        }
        public IPAddress ListenIP
        {
            get { return IPAddress.Parse(listenIP); }
            set { listenIP = value.ToString(); }
        }

        public IPEndPoint EndPoint
        {
            get { return new IPEndPoint(ServerIP, port); }
            set { ListenIP = value.Address; port = value.Port; }
        }
        public string ServerHost
        {
            get { return serverHost; }
            set { serverHost = value; }
        }
        /// <summary>
        /// Resolves Server hostname and returns a random IP assigned to that host.
        /// </summary>
        public IPAddress ServerIP
        {
            get
            {
                if (serverIP == null)
                {
                    Random randomIP = new Random();
                    IPHostEntry serverHostEntry = Dns.GetHostEntry(serverHost);
                    return serverHostEntry.AddressList[randomIP.Next(0, serverHostEntry.AddressList.Length)];
                }
                else { return serverIP; }
            }
            set
            {
                serverIP = value;
            }
        }

        #endregion
    }
}
